//
//  WCButtonForNoti.m
//  WC
//
//  Created by wsj2015 on 16/1/14.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCButtonForNoti.h"

#import "Macros.h"

#define kViewWidth 28
#define kViewHeight 28



@implementation WCButtonForNoti
{
    UIButton *_btn;
    UILabel  *_label;
    
    CGFloat myWidth;
    CGFloat myHeight;
    CGFloat r;

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame withBtnImage:(NSString *)imageName
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor =[UIColor clearColor];
          r = 8;
        _btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [_btn addTarget:self action:@selector(pressAction) forControlEvents:UIControlEventTouchUpInside];
//        [_btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]
        ;
        [_btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//        _btn.backgroundColor = [UIColor blueColor];
        [self addSubview:_btn];
        
        _label =[[UILabel alloc] init];
        _label.backgroundColor = [UIColor redColor];
        _label.textColor = [UIColor whiteColor];
        _label.font =[UIFont systemFontOfSize:10];
        _label.textAlignment = NSTextAlignmentCenter;
        _label.adjustsFontSizeToFitWidth = YES;
        _label.layer.masksToBounds = YES;
        _label.layer.cornerRadius =r;
        [self addSubview:_label];
      
       
        
        
        
    }
    return self;

}
- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    
    myWidth = frame.size.width;
    myHeight = frame.size.height;
    
    
    
}

- (void)setNotiTextClor:(UIColor *)notiTextClor{
    _label.textColor = notiTextClor;
    
}
- (void)setNotiBackroundColor:(UIColor *)notiBackroundColor{
    _label.backgroundColor = notiBackroundColor;
}
- (void)layoutSubviews{
    _btn.frame =CGRectMake(0, 5, myWidth , myHeight );
    
    _label.frame = CGRectMake(myWidth -r *2, 0, 2 *r, 2*r);

    [super layoutSubviews];

}

- (void)pressAction{
    if (self.pressBlock) {
        self.pressBlock();
    }

}
- (void)setNotiR:(CGFloat)notiR{
        r = notiR;
    if (r<8) {
        _label.font = [UIFont systemFontOfSize:8];
    }
    
}
- (void)setNotices:(NSInteger)notices
{
    _notices = notices;
    if (notices == 0) {
        _label.text = @"";
        _label.hidden = YES;
    }else{
        _label.hidden = NO;
        _label.text = [NSString stringWithFormat:@"%i",notices];
    
    }

}

@end
